<h1><?php echo Yii::t('view', 'History'); ?></h1>
<?php $this->widget('bootstrap.widgets.BootAlert'); ?>
<?php 
$form = $this->beginWidget('bootstrap.widgets.BootActiveForm', array(
	'id'=>'input-form',
	'enableAjaxValidation'=>false,
    'htmlOptions'=>array('class'=>'well'),
)); ?>

<?php echo $form->textFieldRow($model, 'string', array('prepend'=>'<i class="icon-search"></i>')); ?>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.BootButton', array('buttonType'=>'submit', 'type'=>'primary', 'icon'=>'icon-search icon-white', 'label'=>Yii::t('view', 'Search'))); ?> 
<?php 
$this->widget('bootstrap.widgets.BootButton', array(
    'label' => Yii::t('view', 'Reset'),
	'icon' => 'icon-remove',
      'url' => array('/history/index'),
));
	?>
</div>
<?php $this->endWidget(); ?>

<p>
<?php
if ($searchResult) { 
	if ($model->string != null) {
		echo Yii::t('view', 'Displaying {count} search results', array('{count}'=>sizeof($searchResult)));
	} else {
		echo Yii::t('view', 'Displaying the last 25 entries. For more results use the search above.');
	}
	?>
	</p>
	<table class="table table-striped table-bordered">
	  	<thead>
	    	<tr>
	    		<th>#</th>
	    		<th><?php echo History::model()->getAttributeLabel('body'); ?></th>
	      		<th><?php echo History::model()->getAttributeLabel('header'); ?></th>
	      		<th><?php echo History::model()->getAttributeLabel('footer'); ?></th>
	      		<th width="130px"><?php echo Yii::t('view', 'Actions'); ?></th>
	    	</tr>
	  	</thead>
	  	<tbody>
	  	<?php 
	  	$n = 1;
	  	
		foreach ($searchResult AS $result) {
			$downloadLink = $result->getDownloadLink();
			?>
			<tr>
				<td rowspan="3">
					<?php $this->widget('bootstrap.widgets.BootBadge', array(
					    'type'=>'', // '', 'success', 'warning', 'error', 'info' or 'inverse'
					    'label'=>$n++,
					)); ?>
				</td>
		      	<td><?php echo $result->body; ?></td>
		      	<td><?php echo htmlspecialchars($result->header); ?></td>
		      	<td><?php echo htmlspecialchars($result->footer); ?></td>
		      	<td>
			      	<?php $this->widget('bootstrap.widgets.BootButton', array(
					    'type'=>'success', 
			      		'url' => array('site/index', 'id'=>$result->uuid),
					    'size'=>'mini', 
			      		'icon'=>'icon-pencil'
					)); ?>
					<?php $this->widget('bootstrap.widgets.BootButton', array(
					    'type' => 'info', 
			      		'url' => array('download/index', 'id'=>$result->uuid),
					    'size' => 'mini', 
						'htmlOptions'=> array('target'=>'_blank'),
						'icon'=>'icon-download'
					)); ?> 
					<?php
					//if ($result->user != 'NULL') {
						if ($result->shared == '1') 
						{ 
							$icon = 'icon-eye-open';
						} 
						else 
						{ 
							$icon = 'icon-eye-close'; 
						}
						
						if ($result->user != 'NULL') 
						{ 
							$disabled = false;
							$url = array('share', 'id' => $result->uuid);
						} 
						else 
						{ 
							$disabled = true; 
							$url = null;
						}
						
						
						
						$this->widget('bootstrap.widgets.BootButton', array(
						    'icon'=> $icon,
						    'type'=>'danger', 
				      		'url' => $url,
						    'size'=>'mini', 
							'htmlOptions' => array('disabled' => $disabled)
						)); 
					//}
					?> 
					<?php 
					if ($downloadLink) {
						$this->widget('bootstrap.widgets.BootButton', array(
						    'type'=>'warning', 
				      		'url' => $downloadLink,
						    'size'=>'mini', 
							'htmlOptions'=> array('target'=>'_blank'),
							'icon'=>'icon-hdd'
						)); 
					}
					?>
		      	</td>
		    </tr>
		    <tr>
		    	<td colspan="2"><?php echo $result->getUniqueTagsList(); ?></td>
		    	<td colspan="2">
		    		<?php 
		    			echo '<i class="icon-time"></i> ' . $result->getTimestamp(); 
		    			echo ' / <i class="icon-globe"></i> ' . $result->uuid; 
		    			echo ' / <i class="icon-pencil"></i> ' . $result->loadCount;
		    			
		    			if ($downloadLink) {
		    				$format = explode('.', $downloadLink);
		    				echo ' / <i class="icon-hdd"></i> ' . $format[1];
		    			}
		    			
						if ($result->user != 'NULL') {
		    				echo ' / <i class="icon-user"></i>';
		    			}
		    		?>
		    	</td>
		    </tr>
		    <tr>
		    	<td colspan="4"><?php if (isset($result->comment)) { echo $result->comment; } else { echo "No comment set"; } ?></td>
		    </tr>
		    <?php
		}
		?>
	  	</tbody>
	</table>
<?php } ?>
